<?php
require_once("vcl/vcl.inc.php");
require_once("lib/db_connection.php");
//Includes
use_unit("forms.inc.php");
use_unit("extctrls.inc.php");
use_unit("stdctrls.inc.php");

//Class definition
class Cost_Create extends Page
{
       public $hfincident = null;
       public $hfVeh = null;
       public $Image1 = null;
       public $btnAdd = null;
       public $edAmt = null;
       public $Label9 = null;
       public $edDesc = null;
       public $Label8 = null;
       function edAmtJSKeyUp($sender, $params)
       {

       ?>
       //Add your javascript code here
       //accept only numbers
       var numero = document.getElementById("edAmt").value;
       var first = numero.indexOf('.');
       var last = numero.lastIndexOf('.');

       while(isNaN(numero))
       {
        haba = numero.length;
        haba = haba - 1;
        numero = numero.substr(0,haba);
       }

       while(first!=last)
       {
        numero = numero.slice(0,last);
        first = numero.indexOf('.');
        last = numero.lastIndexOf('.');
       }
       document.getElementById("edAmt").value = numero;
       <?php

       }

       function Cost_CreateCreate($sender, $params)
       {
       $veh = $_GET['veh'];
       $inc = $_GET['inc'];
       $this->hfVeh->setValue($veh);
       $this->hfincident->setValue($inc);

       if(!isset($_SESSION['rand']))
       {
       $_SESSION['rand'] = rand() . "\n";
       }


       $this->edDesc->Text='';
       $this->edAmt->Text='';

       }


       function btnAddClick($sender, $params)
       {
       $result_cost = mysql_query("insert into incident_cost_tbl (company_id,
       vehicle_id,
       incident_id,
       description,
       amount)

       values ('".$_SESSION['company_id']."',
       '".$this->hfVeh->getValue()."',
       '".$this->hfincident->getValue()."',
       '".$this->edDesc->Text."',
       '".$this->edAmt->Text."')");

       /*echo "<script language=javascript>
       alert('Added record successfully!');
       window.opener.JTIFrameCost.location.reload();
       window.close();
       </script>";*/

       echo "<script type='text/javascript'>
       alert('Added record successfully!');
       var answer = confirm('Add another record?');
       if(answer)
       {
       window.opener.JTIFrameCost.location.reload();
       window.location = 'cost_add.php?veh=".$this->hfVeh->getValue()."&inc=".$this->hfincident->getValue()."';
       }
       else
       {
       window.opener.JTIFrameCost.location.reload();
       window.close();
       }
       </script>";
       }


}

global $application;

global $Cost_Create;

//Creates the form
$Cost_Create=new Cost_Create($application);

//Read from resource file
$Cost_Create->loadResource(__FILE__);

//Shows the form
$Cost_Create->show();

?>